import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import LoginsCSY from '@/components/LoginsCSY/index'
import HomeCSY from '@/components/HomeCSY/index'
import Center from '@/components/MyCenter/index'
import store from '../vuex/store'

import Logins from '@/components/Logins/index'
import Home from '@/components/Home/Home'
import Budget from '@/components/Budget/Budget'
import BudgetTwe from '@/components/Budget/BudgetTwe'

 

Vue.use(Router)


 const router = new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: Logins
    },
    {
      path: '/loginCSY',
      name: 'loginCSY',
      component: LoginsCSY
    },
    {
      path: '/bjyd',
      name: 'home',
      component: HomeCSY
    },
    {
      path: '/center',
      name: 'home',
      component: Center
    },

    {
      path: '/login',
      name: 'login',
      component: Logins
    },
     {
      path: '/Home',
      name: 'Home',
      component: Home
    },
     {
      path: '/Budget',
      name: 'Budget',
      component: Budget
    },
     {
      path: '/BudgetTwe',
      name: 'BudgetTwe',
      component: BudgetTwe
    }
  ]
})

router.beforeEach((to, from, next) => {
  
  
    if (to.path != "/login") {
      const routerPowerArr = store.state.login.authority; //后台返回的路由权限数组
      if (!!routerPowerArr) {
        const arr = routerPowerArr.route;
        arr.push('/Budget','/BudgetTwe','/Home')
        const can = arr.some((item)=>{
          return item == to.path
        });
        if (can) {
          next()
        } else {
          alert("你没得权限")
        }
      }
    } else {
      next()
    }

  })

  export default router